Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ECDSA TSS in external signer #3734

Merged
merged 1 commit into from
Jul 26, 2023

Conversation

islamaminBitGo
Copy link
Contributor

No description provided.

@islamaminBitGo islamaminBitGo force-pushed the HSM-110-external-signer-tss-ecdsa branch 3 times, most recently from d3abd9a to 62304fc Compare July 19, 2023 21:32
@islamaminBitGo islamaminBitGo marked this pull request as ready for review July 19, 2023 21:33
@islamaminBitGo islamaminBitGo requested review from a team as code owners July 19, 2023 21:33
Copy link
Contributor

@zahin-mohammad zahin-mohammad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ready for review yet

@zahin-mohammad zahin-mohammad marked this pull request as draft July 19, 2023 22:26
@islamaminBitGo islamaminBitGo force-pushed the HSM-110-external-signer-tss-ecdsa branch 8 times, most recently from 41b7fd8 to 2903436 Compare July 20, 2023 20:25
@islamaminBitGo islamaminBitGo marked this pull request as ready for review July 20, 2023 21:00
Comment on lines +1608 to +1611
_.isFunction(params.customPaillierModulusGeneratingFunction) &&
_.isFunction(params.customKShareGeneratingFunction) &&
_.isFunction(params.customMuDeltaShareGeneratingFunction) &&
_.isFunction(params.customSShareGeneratingFunction)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Why can't we use
typeof v === 'function'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no particular reason, i came across this first so just used it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but yeah i believe it could be used as well.

@@ -2799,7 +2810,7 @@ export class Wallet implements IWallet {
}

try {
const signedTxRequest = await this.tssUtils!.signUsingExternalSigner(
const signedTxRequest = await this.tssUtils!.signEddsaTssUsingExternalSigner(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you assert tssUtils above? Please don't propagate non-null asserts

* @param params signing options
*/
private async signTransactionTssExternalSignerECDSA(
params: WalletSignTransactionOptions = {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option params should be last.

Comment on lines +2834 to +2858
let txRequestId = '';
if (params.txRequestId) {
txRequestId = params.txRequestId;
} else if (params.txPrebuild && params.txPrebuild.txRequestId) {
txRequestId = params.txPrebuild.txRequestId;
} else {
throw new Error('TxRequestId required to sign TSS transactions with External Signer.');
}

if (!params.customPaillierModulusGeneratingFunction) {
throw new Error('Generator function for paillier modulus required to sign transactions with External Signer.');
}

if (!params.customKShareGeneratingFunction) {
throw new Error('Generator function for K share required to sign transactions with External Signer.');
}

if (!params.customMuDeltaShareGeneratingFunction) {
throw new Error('Generator function for MuDelta share required to sign transactions with External Signer.');
}

if (!params.customSShareGeneratingFunction) {
throw new Error('Generator function for S share required to sign transactions with External Signer.');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it would nice to extract this to its own util function and have unit tests just for this.

}

try {
const signedTxRequest = await this.tssUtils!.signEcdsaTssUsingExternalSigner(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't propagate non-null asserts

switch (req.params.sharetype) {
case 'commitment':
return await eddsaUtils.createCommitmentShareFromTxRequest(req.body);
case 'R':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define these magic strings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ex. ShareType.R

customGShareGeneratingFunction: createCustomGShareGenerator(req.config.externalSignerUrl, req.params.coin),
};
const coin = req.bitgo.coin(req.params.coin);
if (coin.getMPCAlgorithm() === 'eddsa') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

customRShareGeneratingFunction: createCustomRShareGenerator(req.config.externalSignerUrl, req.params.coin),
customGShareGeneratingFunction: createCustomGShareGenerator(req.config.externalSignerUrl, req.params.coin),
};
} else if (coin.getMPCAlgorithm() === 'ecdsa') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

@@ -102,6 +109,208 @@ describe('External signer', () => {
envStub.restore();
});

it('should read an encrypted prv from signerFileSystemPath and pass it to PaillierModulus, K, MuDelta, and S share generators', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any non-happy path tests we can add? What about invalid inputs/configs?

Copy link
Contributor Author

@islamaminBitGo islamaminBitGo Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a lot of missing non-happy path tests for the already supported eddsa external signer as well, i created this ticket to add non-happy path tests for external signer in general cause i think it would make this PR way too big. https://bitgoinc.atlassian.net/browse/HSM-120

Comment on lines +612 to +619
challenges: {
enterpriseChallenge: EcdsaTypes.SerializedEcdsaChallenges;
bitgoChallenge: TxRequestChallengeResponse;
};
prv: string;
derivationPath: string;
walletPassphrase?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: for large types, don't inline them

)) as DShare;

const userSShare = await ECDSAMethods.createUserSignatureShare(
userOmicronAndDeltaShare.oShare,
step2Return.oShare as OShare,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we casting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the case of the hot wallet flow this step2Return would hold the actual OShare which is an OShare object, in the case of external signer it would return an encryptedOShare as a string. This is explained as a comment on the type definition of step2Return.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have better types instead of casting. Casting is almost never the fix for production app code.

zahin-mohammad
zahin-mohammad previously approved these changes Jul 26, 2023
Copy link
Contributor

@zahin-mohammad zahin-mohammad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address comments in a follow up

@islamaminBitGo islamaminBitGo force-pushed the HSM-110-external-signer-tss-ecdsa branch 2 times, most recently from c70efb5 to 3674012 Compare July 26, 2023 20:26
@islamaminBitGo islamaminBitGo merged commit 24c5df6 into master Jul 26, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants